package org.studiox.graph.persistence.mybatis.dao;

import org.apache.ibatis.annotations.*;
import org.studiox.graph.persistence.model.GraphEdgeDO;

import java.util.List;

public interface GraphEdgeDao {

  @Select("select * from graph_edge")
  @Results(
      id = "graphEdgeDOMap",
      value = {
        @Result(id = true, column = "id", property = "id"),
        @Result(column = "content", property = "content"),
        @Result(column = "content_md5", property = "contentMd5"),
        @Result(column = "type", property = "type"),
        @Result(column = "owner", property = "owner"),
        @Result(column = "source_vertex_uniq", property = "sourceVertexUniq"),
        @Result(column = "target_vertex_uniq", property = "targetVertexUniq"),
        @Result(column = "janus_edge_id", property = "janusEdgeId"),
        @Result(column = "neo4j_edge_id", property = "neo4jEdgeId"),
        @Result(column = "nebula_edge_id", property = "nebulaEdgeId"),
        @Result(column = "source_janus_vertex_id", property = "sourceJanusVertexId"),
        @Result(column = "target_janus_vertex_id", property = "targetJanusVertexId"),
        @Result(column = "source_neo4j_vertex_id", property = "sourceNeo4jVertexId"),
        @Result(column = "target_neo4j_vertex_id", property = "targetNeo4jVertexId"),
        @Result(column = "source_nebula_vertex_id", property = "sourceNebulaVertexId"),
        @Result(column = "target_nebula_vertex_id", property = "targetNebulaVertexId"),
        @Result(column = "deleted", property = "deleted"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
      })
  List<GraphEdgeDO> findAll();

  @Insert(
      "insert into graph_edge(content,type,owner,source_vertex_uniq,target_vertex_uniq,janus_edge_id,source_janus_vertex_id,target_janus_vertex_id) "
          + "values (#{content},#{type},#{owner},#{sourceVertexUniq},#{targetVertexUniq},#{janusEdgeId},#{sourceJanusVertexId},#{targetJanusVertexId})")
  void save(GraphEdgeDO graphEdgeDO);

  @Update(
      "update graph_edge set content=#{content},type=#{type},owner=#{owner},source_vertex_uniq=#{sourceVertexUniq},target_vertex_uniq=#{targetVertexUniq},janus_edge_id=#{janusEdgeId},"
          + "source_janus_vertex_id=#{sourceJanusVertexId},target_janus_vertex_id=#{targetJanusVertexId},deleted=#{deleted},update_time=#{updateTime} where id=#{id}")
  void update(GraphEdgeDO graphEdgeDO);

  @Delete("delete from graph_edge where id=#{id}")
  void delete(@Param("id") Long id);

  @Select("select * from graph_edge where id=#{id}")
  GraphEdgeDO findById(@Param("id") Long id);

  @Select("select count(*) from graph_edge")
  int findTotalNum();
}
